package com.dews.quartz.task;


import com.dews.course.service.IDegreeGradeService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 学生成绩相关的定时任务
 *
 * @author 清风学Java
 * @version 1.0.0
 * @date 2025/2/3
 */
@Component
@Slf4j
public class StudentScoreTask {

    private IDegreeGradeService degreeGradeService;

    @Autowired
    public StudentScoreTask(IDegreeGradeService degreeGradeService) {
        this.degreeGradeService = degreeGradeService;
    }

    /**
     * 每日定时统计学生成绩绩点信息
     */
    @XxlJob(value = "statisticsDegreeGrade")
    public void statisticsDegreeGrade() {
        log.info("开始统计学生的课程成绩绩点信息， {}", LocalDateTime.now());
        try {
            degreeGradeService.statisticsDegreeGrade();
        } catch (Exception e) {
            log.error("统计学生课程成绩绩点信息失败， 异常信息：{}", e.getMessage(), e);
        }
        log.info("统计学生课程成绩绩点信息结束， {}", LocalDateTime.now());
    }

    /**
     * 学位预警
     */
    @XxlJob(value = "degreeWarning")
    public void degreeWarning() {
        log.info("开始学位预警， {}", LocalDateTime.now());
        try {
            degreeGradeService.degreeWarning();
        } catch (Exception e) {
            log.error("学位预警失败， 异常信息：{}", e.getMessage(), e);
        }
        log.info("学位预警结束， {}", LocalDateTime.now());
    }

}
